package com.heking.fileselectorlib;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.zhoug.fileselector.beans.LocalMedia;
import com.zhoug.fileselector.selector.FileSelector;
import com.zhoug.fileselector.selector.FileSelectorDialog;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = ">>>MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    FileSelectorDialog fileSelectorDialog;

    public void chooseFile(View view) {
        fileSelectorDialog = new FileSelectorDialog(this);
        fileSelectorDialog.addFlag(FileSelectorDialog.FLAG_ALL);
        FileSelectorDialog.ChooseConfig chooseConfig = fileSelectorDialog.getChooseConfig();
        chooseConfig.captureAudio = true;
        chooseConfig.captureImage = true;
        chooseConfig.captureVideo = true;
        chooseConfig.minDuration = 10;
        chooseConfig.maxNum = 5;
        fileSelectorDialog.setOnSelectListener(new FileSelector.onSelectListener() {
            @Override
            public void onResult(List<LocalMedia> medias) {
                if (medias != null && medias.size() > 0) {
                    for (LocalMedia localMedia : medias) {
                        Log.d(TAG, "onResult:localMedia=" + localMedia);
                    }
                }
            }
        });
        fileSelectorDialog.show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (fileSelectorDialog != null) {
            fileSelectorDialog.onActivityResult(requestCode, resultCode, data);
        }
    }
}